package com.sk.waste.app.adapters

import android.annotation.SuppressLint
import android.content.Context
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.Button
import android.widget.LinearLayout
import android.widget.TextView
import androidx.recyclerview.widget.RecyclerView
import com.lc.smc.lib.interfaces.LCInterface
import com.sk.waste.app.R
import com.sk.waste.app.models.TagModel

/**
 *  @time 2025/01/07  15:37
 *  @desc 兴趣标签
 */
class InterestAdapter(private val context: Context, val list: List<TagModel>, val callback: LCInterface.LcCallBack) :
    RecyclerView.Adapter<InterestAdapter.ViewHolder>() {

    private var currentSelect = 0

    override fun getItemCount(): Int {
        return list.size
    }

    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): InterestAdapter.ViewHolder {
        return ViewHolder(LayoutInflater.from(context).inflate(R.layout.adapter_interest, parent, false))
    }

    @SuppressLint("NotifyDataSetChanged", "SetTextI18n")
    override fun onBindViewHolder(holder: ViewHolder, @SuppressLint("RecyclerView") position: Int) {

        val item = list[position]
        holder.ttvName.text = item.title
        holder.bttLook.tag = position
        holder.bttLook.setOnClickListener {
            currentSelect = holder.bttLook.tag as Int
            callback.callBack(holder.bttLook.id, currentSelect)
        }

        holder.bttEdit.tag = position
        holder.bttEdit.setOnClickListener {
            currentSelect = holder.bttEdit.tag as Int
            callback.callBack(holder.bttEdit.id, currentSelect)
        }

        holder.bttDelete.tag = position
        holder.bttDelete.setOnClickListener {
            currentSelect = holder.bttDelete.tag as Int
            callback.callBack(holder.bttDelete.id, currentSelect)
        }


//        holder.rootView.tag = position
//        holder.rootView.setOnClickListener {
//            currentSelect = holder.rootView.tag as Int
//            callbackListener.callBack(holder.rootView.tag, -1)
//        }

    }


    fun getCurrentSelect(): Int {
        return currentSelect
    }

    inner class ViewHolder(view: View) : RecyclerView.ViewHolder(view) {
        val ttvName: TextView = view.findViewById(R.id.item_interest_name)
        val bttLook: Button = view.findViewById(R.id.item_interest_look)
        val bttEdit: Button = view.findViewById(R.id.item_interest_edit)
        val bttDelete: Button = view.findViewById(R.id.item_interest_delete)
        val rootView: LinearLayout = view.findViewById(R.id.item_root_layout)
    }


}